﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Policy : IAccessible<P_Policy, Policy>, ILogicEntity<P_Policy, Policy>
    {
        public int ID { get; set; }
        public string PolicyName { get; set; }
        public DurationType DurationType { get; set; }
        /// <summary>
        /// 当发布特殊策略时，Duration允许输入0。
        /// 当值为0时表示此策略的Duration值与所绑定的项目的普通策略Duration保持一致
        /// </summary>
        public int Duration { get; set; }
        public BalanceType BalanceType { get; set; }
        public SettlementType SettlementType { get; set; }
        public decimal Rate { get; set; }
        public bool IsAttach { get; set; }
        public ItemStatus Status { get; set; }
        public string CreateUser { get; set; }
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 期数，当期数与项目期数相同时，期数=0；此外期数为具体的数字
        /// </summary>
        public int CycleAmount { get; set; }

        protected override void Covariant(P_Policy model)
        {
            if (model != null)
            {
                this.ID = model.ID;
                this.IsAttach = model.IsAttach;
                this.PolicyName = model.PolicyName;
                this.BalanceType = (BalanceType)model.BalanceType;
                this.SettlementType = (SettlementType)model.SettlementType;
                this.Rate = model.Rate;
                this.Status = (ItemStatus)model.Status;
                this.CreateTime = model.CreateTime;
                this.CreateUser = model.CreateUser;
                this.DurationType = (DurationType)model.DurationType;
                this.Duration = model.Duration;
                this.CycleAmount = model.CycleAmount;
            }
        }

        protected override P_Policy Inverter(Policy model)
        {
            if (model != null)
            {
                return new P_Policy()
                {
                    ID = model.ID,
                    IsAttach = model.IsAttach,
                    PolicyName = model.PolicyName,
                    BalanceType = (int)model.BalanceType,
                    SettlementType = (int)model.SettlementType,
                    Rate = model.Rate,
                    Status = (int)model.Status,
                    CreateTime = model.CreateTime,
                    CreateUser = model.CreateUser,
                    DurationType = (int)model.DurationType,
                    Duration = model.Duration,
                    CycleAmount = model.CycleAmount
                };
            }
            return null;
        }

        public Policy Set(P_Policy dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
